<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.20"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libxlsxwriter: autofilter.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libxlsxwriter
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.20 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">autofilter.c</div>  </div>
</div><!--header-->
<div class="contents">
<table width="600">
<tr>
<td><a class="el" href="merge_rich_string_8c-example.html">&lt;&lt; merge_rich_string.c</a> </td><td align="right"><a class="el" href="data_validate_8c-example.html">data_validate.c &gt;&gt;</a>  </td></tr>
</table>
<p>Example of adding an autofilter to a worksheet.</p>
<div class="image">
<img src="autofilter.png" alt=""/>
</div>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Example of adding an autofilter to a worksheet in Excel using</span></div>
<div class="line"><span class="comment"> * libxlsxwriter.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Copyright 2014-2018, John McNamara, jmcnamara@cpan.org</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;xlsxwriter.h&quot;</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line"> </div>
<div class="line">    <a name="_a0"></a><a class="code" href="structlxw__workbook.html">lxw_workbook</a>  *workbook  = <a name="a1"></a><a class="code" href="workbook_8h.html#a1cf96608a23ee4eb0e8467c15240d00b">workbook_new</a>(<span class="stringliteral">&quot;autofilter.xlsx&quot;</span>);</div>
<div class="line">    <a name="_a2"></a><a class="code" href="structlxw__worksheet.html">lxw_worksheet</a> *worksheet = <a name="a3"></a><a class="code" href="workbook_8h.html#a81d456b4f65a464e78e4a0030ecc3c2e">workbook_add_worksheet</a>(workbook, NULL);</div>
<div class="line">    uint16_t i;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Simple data structure to represent the row data. */</span></div>
<div class="line">    <span class="keyword">struct </span>row {</div>
<div class="line">        <span class="keywordtype">char</span> region[16];</div>
<div class="line">        <span class="keywordtype">char</span> item[16];</div>
<div class="line">        <span class="keywordtype">int</span>  volume;</div>
<div class="line">        <span class="keywordtype">char</span> month[16];</div>
<div class="line">    };</div>
<div class="line"> </div>
<div class="line">    <span class="keyword">struct </span>row data[] = {</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Apple&quot;</span>,   9000, <span class="stringliteral">&quot;July&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Apple&quot;</span>,   5000, <span class="stringliteral">&quot;July&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Orange&quot;</span>,  9000, <span class="stringliteral">&quot;September&quot;</span> },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Apple&quot;</span>,   2000, <span class="stringliteral">&quot;November&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Apple&quot;</span>,   9000, <span class="stringliteral">&quot;November&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Pear&quot;</span>,    7000, <span class="stringliteral">&quot;October&quot;</span>   },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Pear&quot;</span>,    9000, <span class="stringliteral">&quot;August&quot;</span>    },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Orange&quot;</span>,  1000, <span class="stringliteral">&quot;December&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   1000, <span class="stringliteral">&quot;November&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Pear&quot;</span>,   10000, <span class="stringliteral">&quot;April&quot;</span>     },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   6000, <span class="stringliteral">&quot;January&quot;</span>   },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Orange&quot;</span>,  3000, <span class="stringliteral">&quot;May&quot;</span>       },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Apple&quot;</span>,   3000, <span class="stringliteral">&quot;December&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Apple&quot;</span>,   7000, <span class="stringliteral">&quot;February&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   1000, <span class="stringliteral">&quot;December&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   8000, <span class="stringliteral">&quot;February&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Grape&quot;</span>,  10000, <span class="stringliteral">&quot;June&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Pear&quot;</span>,    7000, <span class="stringliteral">&quot;December&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Apple&quot;</span>,   2000, <span class="stringliteral">&quot;October&quot;</span>   },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   7000, <span class="stringliteral">&quot;December&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Grape&quot;</span>,   6000, <span class="stringliteral">&quot;April&quot;</span>     },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Pear&quot;</span>,    8000, <span class="stringliteral">&quot;February&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Apple&quot;</span>,   7000, <span class="stringliteral">&quot;August&quot;</span>    },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Orange&quot;</span>,  7000, <span class="stringliteral">&quot;July&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Apple&quot;</span>,   6000, <span class="stringliteral">&quot;June&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Grape&quot;</span>,   8000, <span class="stringliteral">&quot;September&quot;</span> },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Apple&quot;</span>,   3000, <span class="stringliteral">&quot;October&quot;</span>   },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Orange&quot;</span>, 10000, <span class="stringliteral">&quot;November&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   4000, <span class="stringliteral">&quot;July&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Orange&quot;</span>,  5000, <span class="stringliteral">&quot;August&quot;</span>    },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Orange&quot;</span>,  1000, <span class="stringliteral">&quot;November&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Orange&quot;</span>,  4000, <span class="stringliteral">&quot;October&quot;</span>   },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Grape&quot;</span>,   5000, <span class="stringliteral">&quot;August&quot;</span>    },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Apple&quot;</span>,   1000, <span class="stringliteral">&quot;December&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Apple&quot;</span>,   10000, <span class="stringliteral">&quot;March&quot;</span>    },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   7000, <span class="stringliteral">&quot;October&quot;</span>   },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   1000, <span class="stringliteral">&quot;September&quot;</span> },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,  10000, <span class="stringliteral">&quot;October&quot;</span>   },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Orange&quot;</span>,  8000, <span class="stringliteral">&quot;March&quot;</span>     },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Apple&quot;</span>,   4000, <span class="stringliteral">&quot;July&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Orange&quot;</span>,  5000, <span class="stringliteral">&quot;July&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;West&quot;</span>,  <span class="stringliteral">&quot;Apple&quot;</span>,   4000, <span class="stringliteral">&quot;June&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Apple&quot;</span>,   5000, <span class="stringliteral">&quot;April&quot;</span>     },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Pear&quot;</span>,    3000, <span class="stringliteral">&quot;August&quot;</span>    },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   9000, <span class="stringliteral">&quot;November&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Orange&quot;</span>,  8000, <span class="stringliteral">&quot;October&quot;</span>   },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Apple&quot;</span>,  10000, <span class="stringliteral">&quot;June&quot;</span>      },</div>
<div class="line">        {<span class="stringliteral">&quot;South&quot;</span>, <span class="stringliteral">&quot;Pear&quot;</span>,    1000, <span class="stringliteral">&quot;December&quot;</span>  },</div>
<div class="line">        {<span class="stringliteral">&quot;North&quot;</span>, <span class="stringliteral">&quot;Grape&quot;</span>,   10000, <span class="stringliteral">&quot;July&quot;</span>     },</div>
<div class="line">        {<span class="stringliteral">&quot;East&quot;</span>,  <span class="stringliteral">&quot;Grape&quot;</span>,   6000, <span class="stringliteral">&quot;February&quot;</span>  }</div>
<div class="line">    };</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Write the column headers. */</span></div>
<div class="line">    <a name="a4"></a><a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, 0, 0, <span class="stringliteral">&quot;Region&quot;</span>, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, 0, 1, <span class="stringliteral">&quot;Item&quot;</span>,   NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, 0, 2, <span class="stringliteral">&quot;Volume&quot;</span> , NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, 0, 3, <span class="stringliteral">&quot;Month&quot;</span>,  NULL);</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Write the row data. */</span></div>
<div class="line">    <span class="keywordflow">for</span> (i = 0; i &lt; <span class="keyword">sizeof</span>(data)/<span class="keyword">sizeof</span>(<span class="keyword">struct</span> row); i++) {</div>
<div class="line">        <a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, i + 1, 0, data[i].region, NULL);</div>
<div class="line">        <a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, i + 1, 1, data[i].item,   NULL);</div>
<div class="line">        <a name="a5"></a><a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, i + 1, 2, data[i].volume , NULL);</div>
<div class="line">        <a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, i + 1, 3, data[i].month,  NULL);</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Add the autofilter. */</span></div>
<div class="line">    <a name="a6"></a><a class="code" href="worksheet_8h.html#a4e2b1de34e96331000a996f512aecfcf">worksheet_autofilter</a>(worksheet, 0, 0, 50, 3);</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> <a name="a7"></a><a class="code" href="workbook_8h.html#ad9e7aeebc0fd43562db5bcd527b2ee5e">workbook_close</a>(workbook);</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<div class="ttc" id="aworksheet_8h_html_a4e2b1de34e96331000a996f512aecfcf"><div class="ttname"><a href="worksheet_8h.html#a4e2b1de34e96331000a996f512aecfcf">worksheet_autofilter</a></div><div class="ttdeci">lxw_error worksheet_autofilter(lxw_worksheet *worksheet, lxw_row_t first_row, lxw_col_t first_col, lxw_row_t last_row, lxw_col_t last_col)</div><div class="ttdoc">Set the autofilter area in the worksheet.</div></div>
<div class="ttc" id="aworkbook_8h_html_ad9e7aeebc0fd43562db5bcd527b2ee5e"><div class="ttname"><a href="workbook_8h.html#ad9e7aeebc0fd43562db5bcd527b2ee5e">workbook_close</a></div><div class="ttdeci">lxw_error workbook_close(lxw_workbook *workbook)</div><div class="ttdoc">Close the Workbook object and write the XLSX file.</div></div>
<div class="ttc" id="aworkbook_8h_html_a1cf96608a23ee4eb0e8467c15240d00b"><div class="ttname"><a href="workbook_8h.html#a1cf96608a23ee4eb0e8467c15240d00b">workbook_new</a></div><div class="ttdeci">lxw_workbook * workbook_new(const char *filename)</div><div class="ttdoc">Create a new workbook object.</div></div>
<div class="ttc" id="astructlxw__worksheet_html"><div class="ttname"><a href="structlxw__worksheet.html">lxw_worksheet</a></div><div class="ttdoc">Struct to represent an Excel worksheet.</div><div class="ttdef"><b>Definition:</b> worksheet.h:1603</div></div>
<div class="ttc" id="astructlxw__workbook_html"><div class="ttname"><a href="structlxw__workbook.html">lxw_workbook</a></div><div class="ttdoc">Struct to represent an Excel workbook.</div><div class="ttdef"><b>Definition:</b> workbook.h:273</div></div>
<div class="ttc" id="aworksheet_8h_html_ac208046e7a6d12cc87982422efa41b31"><div class="ttname"><a href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a></div><div class="ttdeci">lxw_error worksheet_write_string(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *string, lxw_format *format)</div><div class="ttdoc">Write a string to a worksheet cell.</div></div>
<div class="ttc" id="aworksheet_8h_html_ad9fc47d3beaa2ab4759414e8580c2289"><div class="ttname"><a href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a></div><div class="ttdeci">lxw_error worksheet_write_number(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, double number, lxw_format *format)</div><div class="ttdoc">Write a number to a worksheet cell.</div></div>
<div class="ttc" id="aworkbook_8h_html_a81d456b4f65a464e78e4a0030ecc3c2e"><div class="ttname"><a href="workbook_8h.html#a81d456b4f65a464e78e4a0030ecc3c2e">workbook_add_worksheet</a></div><div class="ttdeci">lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)</div><div class="ttdoc">Add a new worksheet to a workbook.</div></div>
<!-- HTML footer for doxygen 1.8.20-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Copyright 2014-2020 John McNamara.
Generated by&#160;<a href="http://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20
</small></address>
</body>
</html>
